package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.anno.MyLog3;
import com.itheima.mapper.PersonMapper;
import com.itheima.mapper.TbCourseMapper;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Person;
import com.itheima.pojo.TbCourse;
import com.itheima.service.TbCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class TbCourseServicempl implements TbCourseService {
    @Autowired
   private  PersonMapper personMapper;
    @Autowired
    private TbCourseMapper tbCourseMapper;
    @Override
    public Person login(Person person) {
        Person e= personMapper.login(person);
        return e;
    }
   @MyLog3
    @Override
    public PageBean seleteCousePage(String code, String name, String applicablePerson, String subject, LocalDateTime createTime, Integer page, Integer pageSize) {

            PageHelper.startPage(page,pageSize);
            List<TbCourse> ClazzList=  tbCourseMapper.list(code,  name,  applicablePerson,  subject, createTime);
            Page<TbCourse> p= (Page<TbCourse>) ClazzList;
            PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
            return pageBean;

    }

    @Override
    public void save(TbCourse tbCourse) {

            tbCourse.setCreateTime(LocalDateTime.now());

            tbCourseMapper.save(tbCourse);

    }

    @Override
    public void deleteStudentById(List<Integer> ids) {
        tbCourseMapper.deleteStudentById(ids);
    }

    @Override
    public TbCourse getById(Integer id) {
        return tbCourseMapper.findById(id);
    }

    @Override
    public void update(TbCourse tbCourse) {


        tbCourseMapper.update(tbCourse);
    }

}
